package org.lwz.space.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.lwz.space.dao.ArticleDao;
import org.lwz.space.dao.ArticleTypeDao;
import org.lwz.space.model.Article;
import org.lwz.space.model.ArticleType;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Liaowz on 2015/10/16.
 */
@Repository(value = "articleTypeDao")
public class ArticleTypeDaoImpl extends BaseDaoImpl<ArticleType> implements ArticleTypeDao {

    @Override
    public ArticleType getArticleType(String name) {
        Query query = getSession().createQuery("from ArticleType where name=:name");
        query.setParameter("name", name);
        return (ArticleType) query.uniqueResult();
    }

    @Override
    public void deleteByName(String name) {
        //TODO:通过名字来删除文章类型  delete ArticleType where name=:name
        ArticleType articleType = getArticleType(name);
        delete(articleType);
    }

}
